package com.mySampleApplication.client.codeRule;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.util.BooleanCallback;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.*;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.CloseClickEvent;
import com.smartgwt.client.widgets.events.CloseClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.types.Overflow;


public class CodingSpecificationwindow {

    public static Window getShowWindow(int width, int height, String title, ListGridRecord record, ListGrid listGrid,String id, String name){
        final Window winModal = new Window();
        winModal.setWidth(width);
        winModal.setHeight(height);
        winModal.setTitle(title);
        winModal.setShowMinimizeButton(false);
        winModal.setIsModal(true);
        winModal.setShowModalMask(true);
        winModal.setCanDragReposition(true);
        winModal.setCanDragResize(true);
        winModal.centerInPage();
        winModal.addCloseClickHandler(new CloseClickHandler() {
            public void onCloseClick(CloseClickEvent event) {
                winModal.destroy();
            }
        });

        VLayout layout = new VLayout();
        layout.setMembersMargin(5);
        layout.setPadding(5);

        final RichTextEditor richTextEditor = new RichTextEditor();
        richTextEditor.setHeight(300);
        richTextEditor.setOverflow(Overflow.HIDDEN);
        richTextEditor.setCanDragResize(true);
        richTextEditor.setShowEdges(true);

        if(record!=null){
            richTextEditor.setValue(record.getAttribute("bmgf"));
        }


        layout.addMember(richTextEditor);

        Button addButton = new Button("determine");
        addButton.setTitle("下一步");
        addButton.setShowRollOver(true);
        addButton.setShowDown(true);
        addButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
//                SC.say(richTextEditor.getValue());
                if(record!=null){
                    record.setAttribute("bmgf",richTextEditor.getValue());
                }
                Window dialog= CodeRuleWindow.getShowWindow(0,1000,700,"(3/5)编辑编码信息", record,listGrid,false,id,name,richTextEditor.getValue(),"bj",null);
                dialog.show();
                winModal.hide();
            }
        });
        Button cancelButton = new Button("关闭");
        cancelButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                SC.ask("关闭操作不会进行数据保存！是否关闭?", new BooleanCallback() {
                    public void execute(Boolean value) {
                        if (value != null && value) {
                            winModal.hide();
                        } else {

                        }
                    }
                });
            }
        });

        HLayout buttonLayout = new HLayout();
        buttonLayout.setMembersMargin(10);
        buttonLayout.setAlign(Alignment.RIGHT);
        buttonLayout.addMembers(addButton,cancelButton);
        buttonLayout.setPadding(5);
        winModal.addItem(layout);
        winModal.addItem(buttonLayout);
        layout.draw();

        return winModal;
    }
}
